package com.javasm.Utils;
import java.sql.*;

/**
 * @author gfs
 * @version 0.1
 * @className JDBCHealper
 * @descriptioin:
 * @date 2024/11/20 16:06
 * @since jdk11
 */
public class JDBCHealper {
    static{

/*
* jdbc.username=root
jdbc.password=root
jdbc.url=jdbc:mysql://127.0.0.1:3306/mydb
jdbc.driver=com.mysql.cj.jdbc.Driver
*
* */
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }


    }
    public static Connection getConn(){
        Connection connection  = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mydb", "root", "123456");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return connection;
    }

    public static void closConn(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet){
        try{
            if(resultSet!=null){
                resultSet.close();
            }
            if(preparedStatement!=null){
                preparedStatement.close();
            }
            if(connection!=null){
                connection.close();
            }
        }catch (SQLException e){
            e.printStackTrace();
        }

    }


}
